package com.njchy.statistics;

import com.njchy.statistics.util.QueryWlanAddressUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication
@MapperScan("com.njchy.statistics.mapper")
public class StatisticsApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext run1 = SpringApplication.run(StatisticsApplication.class, args);
        ConfigurableEnvironment env = run1.getEnvironment();
        // 获取IPv4的本地地址，或者是int地址
        String address;
        if (QueryWlanAddressUtil.getWlan() != null) {
            address = QueryWlanAddressUtil.getWlan();
        } else {
            address = QueryWlanAddressUtil.getInt();
        }
        String swaggerMes =
                "\n**********************************************************\n" +
                        "*                                                          *\n" +
                        "*                     服 务 启 动 成 功                      *\n" +
                        "*                                                          *\n" +
                        "************************************************************\n" +
                        "swagger: \thttp://" + address + ":" + env.getProperty("server.port") + "/doc.html" +
                        "\n************************************************************\n\t";
        log.info(swaggerMes);
        long maxHeap = Runtime.getRuntime().maxMemory() / 1024 / 1024; // 单位：MB
        long initHeap = Runtime.getRuntime().totalMemory() / 1024 / 1024;
        log.info("JVM初始堆内存：" + initHeap + "MB");
        log.info("JVM最大堆内存：" + maxHeap + "MB");
    }

}
